<%--
  Created by IntelliJ IDEA.
  User: 肖
  Date: 2020/10/3
  Time: 19:12
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<br>
<div class="row" style="margin-top: 10px;">
    <div class="col-md-6">
        <button id="yuyues" type="button" class="btn btn-primary btn-sm">
            <span class="glyphicon glyphicon-refresh"></span>刷新
        </button>
        <button id="more_del_btn_yuyue"  type="button" class="btn btn-danger btn-sm">
            <span class=" glyphicon glyphicon-trash"></span>批量删除
        </button>

    </div>
    <div class="col-md-6" style="float: right;">
        <form class="bs-example bs-example-form" role="form">
            <div class="row">
                <div class="input-group input-group-sm col-md-6" style="margin: 0 auto;">
                    <input type="text" id="yuyuesearch" class="form-control" placeholder="请输入" value="${search}">
                    <span class="input-group-btn">
                                    <button id="yuyuebutton" class="btn btn-default btn-primary" type="button">
                                        <span class="glyphicon glyphicon-search"></span>&nbsp搜索
                                </button>
                                </span>
                </div>
            </div>
        </form>
    </div>
</div>
<div class="tab-pane fade in active" >
    <table class="table table-hover table-responsive">
        <%--                <caption>所有预约客户必须通过电话验证</caption>--%>
        <thead>
        <tr>
            <th><input id="ck_all_yuyue" type="checkbox"></th>
            <th>预约时间</th>
            <th>姓名</th>
            <th>电话</th>
            <th>车ID</th>
            <th>车牌</th>


            <th>操作</th>
        </tr>
        </thead>
        <tbody>
        <c:forEach items="${page.list}" var="p" varStatus="vs">
            <tr>
                <th><input value="${p.id}" name="ck_content_yuyue" type="checkbox"></th>

                <th><fmt:formatDate value='${p.resTime}' pattern='yyyy-MM-dd' /></th>
                <th>${p.uname}</th>
                <th>${p.uphone}</th>
                <th>${p.resCarId}</th>
                <th>${p.carCarnumber}</th>



                <td>
                    <button type="button" id="yok" onclick='yuyueok(this,${p.id})' class="btn btn-success">成功</button>
                    <a onclick='del(this,${p.id})' class="text-danger" href="#"><span class="glyphicon glyphicon-trash"></span></a>
                </td>
            </tr>
        </c:forEach>
        </tbody>
    </table>
</div>
<script src="${pageContext.request.contextPath}/plugins/jquery/jquery.min.js"></script>
<script src="${pageContext.request.contextPath}/plugins/bootstrap-3.3.7-dist/js/bootstrap.min.js"></script>
<script>

    //批量删除start
    $(function(){
        let ck = document.getElementById("ck_all_yuyue");
        let cks = document.getElementsByName("ck_content_yuyue");
        ck.onclick=function(){
            if(ck.checked){
                for(let i=0;i<cks.length;i++){
                    cks[i].checked=true;
                }
            }else{
                for(let i=0;i<cks.length;i++){
                    cks[i].checked=false;
                }
            }
        }
    });
    $(function(){
        document.getElementById("more_del_btn_yuyue").onclick=function(){

            let cks = document.getElementsByName("ck_content_yuyue");
            let count = 0;
            for(let i=0;i<cks.length;i++){
                if(cks[i].checked){
                    count++;
                }
            }
            if(count==0){
                alert("请先选中!");
                return;
            }
            let flag = confirm("确定删除吗?");
            if(flag){
                let sids = "";
                for(let i=0;i<cks.length;i++){
                    if(cks[i].checked){
                        sids+=cks[i].value+":";
                    }
                }
                $.post('/prj/seller/delallyuyue',{"sid":sids},function(data){
                    if(data.code=="200"){
                        $("#outer").load("/prj/seller/view",{id:selid});
                    }
                })

            }
        };
    });



//异步刷新
    $("#yuyues").click(function () {

        $("#outer").load("/prj/seller/view",{id:selid});
    })

    //全局搜索
    $("#yuyuebutton").click(function () {
        let search = $("#yuyuesearch").val();
        $("#outer").load("/prj/seller/view",{id:selid,search:search});
    })

    //异步删除
    function del(obj,id){
        $.post('/prj/seller/del',{"id":id},function(data){
            if(data.code=="200"){

                let tr = obj.parentElement.parentElement;
                $(tr).remove();
            }
        })
    }
    //预约成功

    function yuyueok(obj,id){

        $.post('/prj/seller/yuyueokdel',{"id":id},function(data){
            if(data.code=="200"){
                let tr = obj.parentElement.parentElement;
                $(tr).remove();
                $("#yok").load("${pageContext.request.contextPath}/seller/yok",{id:selid})
            }
        })
    }

</script>
<%@include file="../page/salesReservePage.jsp" %>